// -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	SmartLib
//  File name:	ObjectLocker.cs
//  Developer:	Igor Solomatov
//  Created:	15.03.2013
// 
// -------------------- iSharePoint -------------------- //

using System;
using System.Threading;

namespace Smart
{
	/// <summary>
	/// Standard locker
	/// </summary>
	public struct ObjectLocker : IDisposable
	{
		private object _lockObj;

		public ObjectLocker(object lockObj)
		{
			_lockObj = lockObj;

			Monitor.Enter(lockObj);
		}

		public void Dispose()
		{
			if (_lockObj == null) throw new InvalidOperationException("Lock is already freed!");

			Monitor.Exit(_lockObj);
			_lockObj = null;
		}
	}
}